/*
 * @Author: Royce
 * @Date:2019-07-16
 * @des:[]
 * @flow
 */
import React, { Component } from 'react';
import { SafeAreaView, StyleSheet, View, Text, Button, ScrollView } from 'react-native';
import {ListViewEmpty } from '../hoc/EmptyViews';
import {RefreshState} from '@ecool/react-native-ui';
import {observable, action, runInAction} from 'mobx';
import {observer} from 'mobx-react';
import DLFetch from '@ecool/react-native-dlfetch';

interface Props {
    navigation: Object
}

@observer
export default class ListEmpty extends Component<Props> {

    @observable
    dataSource:Array = [];

    constructor(props: Props) {
        super(props);
        this.state = {
            refreshState: RefreshState.Idle,
        };
    }


    @action
    loadErrorOrders = async () => {
        try {
            const data = await DLFetch.postFullUrl('https://sst.hzecoodld.com/spb/api.do?_cid=spb11d&_tid=2170&apiKey=ec-spsales-salesBill-findBills&pageNo=1&pageSize=10&statusType=0&dlProductCode=slhMallAssistIOS&dlProductVersion=3.1.0&deviceType=26&sessionId=ssg10d-18-7BA09F85-C0A6-BAB8-7808-39C77B36AE78');
            runInAction(()=>{
                this.dataSource = data.data.rows;
            });
            return Promise.resolve(data);
        } catch (e) {
            return Promise.reject(e);
        }
    };
    @action
    loadOrders = async () => {
        try {
            const data = await DLFetch.postFullUrl('https://sst.hzecool.com/spb/api.do?_cid=spb11d&_tid=2170&apiKey=ec-spsales-salesBill-findBills&pageNo=1&pageSize=10&statusType=0&dlProductCode=slhMallAssistIOS&dlProductVersion=3.1.0&deviceType=26&sessionId=ssg10d-18-7BA09F85-C0A6-BAB8-7808-39C77B36AE78');
            runInAction(()=>{
                this.dataSource = data.data.rows;
            });
            return Promise.resolve(data);
        } catch (e) {
            return Promise.reject(e);
        }
    };


    render() {
        return (
            <SafeAreaView style={styles.wrap}>
                <ListViewEmpty
                    renderItem={this.renderItem}
                    data={this.dataSource.slice()}
                    refreshState={this.state.refreshState}
                    keyExtractor={(item, index) => index.toString()}
                    onReloadHandler={this.loadErrorOrders}
                    onHeaderRefresh={this.loadOrders}
                />
            </SafeAreaView>
        );
    }

    renderItem = ({ item }) => {
        return <Text>{item.bill.buyerName}</Text>
    }
}

const styles = StyleSheet.create({
    wrap: {
        flex: 1,
        backgroundColor: '#eee'
    },

});
